/**
 * Created by liuyanjun on 2017/6/26.
 */
import {
  RECODE_USERINFO,
  GET_USERINFO,
  RETSET_NAME
}from './mutation-types'

import {
  setStore,
  getStore
}from '../config/mUtils'

export default {
  //记录用户信息
  [RECODE_USERINFO](state,info){
    state.userInfo = info;
    state.login = true;
    let validity = 30;
    let now = new Date();
    now.setTime(now.getTime()+validity*24*60*60*1000);
    document.cookie="USERID="+info.user_id+";expires="+now.toGMTString();
    document.cookie = "SID=huRyTRd9QLij7NkbpHJoj3PQrx1eRiO6bAiw" + ";expires=" + now.toGMTString();
  },
  //获取用户信息存入vuex
  [GET_USERINFO](state,info){
    if(state.userInfo && (state.userInfo.username !== info.username)){
      return;
    }
    if(!state.login){
      return;
    }
    if(!info.message){
      state.userInfo ={...info};
      let validity=30;
      let now = new Date();
      now.setTime(now.getTime()+validity*30*60*60*1000);
      document.cookie = "USERID=" + info.user_id + ";expires=" + now.toGMTString();
      document.cookie = "SID=huRyTRd9QLij7NkbpHJoj3PQrx1eRiO6bAiw" + ";expires=" + now.toGMTString();
    }else{
      state.userInfo=null;
    }
  },
  [RETSET_NAME](state,username){
    state.userInfo=Object.assign({},state.userInfo,{username});
  }






}
